import logging
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from common.log_tools import log
class BasePage1:
    def __init__(self,driver=None):
        if driver is not None:
            self.driver = driver
        else:
            self.driver=webdriver.Chrome()
            self.driver.maximize_window()
            self.driver.implicitly_wait(10)
#封装行为:输入文本框
    def input(self,target,value):
        self.element_locate(target).send_keys(value)
        #self.driver.find_element().send_keys()
    def element_locate(self, target):
        try:#"元素定位方法，定位语句"
            methond,value = self.convert(target)
            return self.driver.find_element(methond,value)
        except Exception as e:
            log.error(e)
            raise (e)
    def convert(self, target):
        method , value=target.split(',')
        return method.strip() , value.strip()
    def click(self,target):
        self.element_locate(target).click()
    def get_ele_text(self,target):
        return self.element_locate(target).text
    def into_frame(self,frame_name):
        self.driver.switch_to.frame(frame_name)
    def wait(self,num):
        time.sleep(num)
    def open(self,url):
        self.driver.get(url)
    def dropdown(self,target,A):
        self.ele=self.element_locate(target)
        self.sle_obj=Select(self.ele)
        self.sle_obj.select_by_value(A)
    def dropdown1(self,target,A):
        self.ele=self.element_locate(target)
        self.sle_obj=Select(self.ele)
        self.sle_obj.select_by_index(A)
    def quit(self):
        self.driver.quit()
if __name__ == '__main__':
    bg = BasePage1()
    bg.open("http://localhost/ranzhi/www/sys/user-login-L3JhbnpoaS93d3cvY3JtL2N1c3RvbWVyLWJyb3dzZS5odG1s.html")
    bg.wait(1)
    bg.input("id,account","123456")
    bg.wait(1)
    bg.input("id,password","123456")
    bg.wait(1)
    bg.click("id,submit")
    bg.wait(5)